﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace syc.Produce.Report
{
    public partial class 月份原辅料采购计划完成情况 : System.Web.UI.Page
    {
        protected HSSFWorkbook hssfworkbook;
        protected double tggplant;//原料套管计划购进量
        protected double tggN80plant;//原料套管N80计划购进量
        protected double yggplant;//原料油管计划购进量
        protected double ygjgplant;//原料油管接箍计划购进量
        protected double tgjgplant;//原料套管接箍计划购进量
        protected double cpjgplant;//成品接箍计划购进量

        protected int yglbhlant;//油管螺纹保护环计划购进量
        protected int tglbhlant;//套管螺纹保护环计划购进量
        protected int 稀释剂plant;//稀释剂计划购进量
        protected int 黑色油漆plant;//黑色油漆计划购进量
        protected int 打包带plant;//油漆计划购进量
        protected double 螺纹脂plant;//螺纹脂计划购进量
        protected double 白色环漆plant;//白色环漆计划购进量
        protected double 接箍漆plant;//接箍漆计划购进量
        protected int 白墨plant;//白墨计划购进量
        protected int 草支垫plant;//草支垫计划购进量

        protected double tgg本月购进;//原料套管本月购进
        protected double tggN80本月购进;//原料套管本月购进
        protected double ygg本月购进;//原料油管本月购进
        protected double ygjg本月购进;//原料油管接箍本月购进
        protected double tgjg本月购进;//原料套管接箍本月购进
        protected double cpjg本月购进;//成品接箍本月购进
        protected int yglbh本月购进;//油管螺纹保护环库存
        protected int tglbh本月购进;//套管螺纹保护环库存
        protected double 稀释剂本月购进;//稀释剂本月购进
        protected double 黑色油漆本月购进;//黑色油漆本月购进
        protected double 打包带本月购进;//油漆本月购进
        protected double 螺纹脂本月购进;//螺纹脂本月购进
        protected double 白色环漆本月购进;//白色环漆本月购进
        protected double 接箍漆本月购进;//接箍漆本月购进
        protected int 白墨本月购进;//白墨本月购进
        protected int 草支垫本月购进;//草支垫本月购进

        protected double tgg完成率;//原料套管本月完成率
        protected double tggN80完成率;//原料套管本月完成率
        protected double ygg完成率;//原料油管本月完成率
        protected double ygjg完成率;//原料油管接箍本月完成率
        protected double tgjg完成率;//原料套管接箍本月完成率
        protected double cpjg完成率;//成品接箍本月完成率
        protected double yglbh完成率;//油管螺纹保护环完成率
        protected double tglbh完成率;//套管螺纹保护环完成率
        protected double 稀释剂完成率;//稀释剂本月完成率
        protected double 黑色油漆完成率;//黑色油漆本月完成率
        protected double 打包带完成率;//油漆本月完成率
        protected double 螺纹脂完成率;//螺纹脂本月完成率
        protected double 白色环漆完成率;//白色环漆本月完成率
        protected double 接箍漆完成率;//接箍漆本月完成率
        protected double 白墨完成率;//白墨本月完成率
        protected double 草支垫完成率;//草支垫本月完成率

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.Year0.SelectedValue = DateTime.Today.Year.ToString();
                this.Month0.SelectedValue = DateTime.Today.Month.ToString();
                ((TextBox)this.FindControl("R" + 1)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 1)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 2)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 2)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 3)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 3)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 4)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 4)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 5)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 5)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 6)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 6)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 7)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 7)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 8)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 8)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 9)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 9)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 10)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 10)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 11)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 11)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 12)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 12)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 13)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 13)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 14)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 14)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 15)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 15)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 16)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 16)).CssClass = "blank_center";
                Button_Query_Click(null, null);
            }
        }

        protected void Button_Query_Click(object sender, EventArgs e)
        {
            ((TextBox)this.FindControl("R" + 1)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 1)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 2)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 2)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 3)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 3)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 4)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 4)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 5)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 5)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 6)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 6)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 7)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 7)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 8)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 8)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 9)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 9)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 10)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 10)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 11)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 11)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 12)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 12)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 13)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 13)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 14)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 14)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 15)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 15)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 16)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 16)).CssClass = "blank_center";
            //计划购进
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            string sql0= @"
            declare @套管螺纹保护环 int
            declare @油管螺纹保护环 int
            declare @稀释剂1 int
            declare @稀释剂2 int
            declare @稀释剂 int         
            declare @油漆1 int
            declare @油漆2 int
            declare @油漆 int        
            declare @打包带 int 
            declare @螺纹脂 float
            declare @色环漆 float
            declare @接箍漆 float
            declare @白墨 int
            declare @草支垫 int

            declare @油管光管 float
            declare @套管光管 float
            declare @套管N80光管 float
            declare @油管接箍光管 float
            declare @套管接箍光管 float
            declare @成品接箍 float   
       
            select @套管螺纹保护环=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0700000002 and 年度=@年度 and 月份=@月份 
            select @油管螺纹保护环=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0700000001 and 年度=@年度 and 月份=@月份
            select @稀释剂1=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0301000003 and 年度=@年度 and 月份=@月份
            select @稀释剂2=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0301000004 and 年度=@年度 and 月份=@月份
            select @油漆1=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0301000001 and 年度=@年度 and 月份=@月份
            select @油漆2=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0301000002 and 年度=@年度 and 月份=@月份 
            select @稀释剂=@稀释剂1+@稀释剂2
            select @油漆=@油漆1+@油漆2
            select @打包带=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0401000001 and 年度=@年度 and 月份=@月份 
            select @螺纹脂=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0302000001 and 年度=@年度 and 月份=@月份
            select @色环漆=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0301000006 and 年度=@年度 and 月份=@月份
            select @接箍漆=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0301000005 and 年度=@年度 and 月份=@月份 
            select @白墨=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0303000007 and 年度=@年度 and 月份=@月份 
            select @草支垫=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0700000003 and 年度=@年度 and 月份=@月份 

            select @油管光管=isnull(sum(计划购进量),0) from 生产处月原料采购计划 where 原料ID=1 and 年度=@年度 and 月份=@月份          
            select @套管光管=isnull(sum(计划购进量),0) from 生产处月原料采购计划  where 原料ID=2 and 年度=@年度 and 月份=@月份  
            select @套管N80光管=isnull(sum(计划购进量),0) from 生产处月原料采购计划  where 原料ID=102 and 年度=@年度 and 月份=@月份  
            select @油管接箍光管=isnull(sum(计划购进量),0) from 生产处月原料采购计划 where 原料ID=3 and 年度=@年度 and 月份=@月份          
            select @套管接箍光管=isnull(sum(计划购进量),0) from 生产处月原料采购计划 where 原料ID=4 and 年度=@年度 and 月份=@月份 
            select @成品接箍=isnull(sum(计划购进量),0) from 生产处月原料采购计划 where 原料ID=6 and 年度=@年度 and 月份=@月份
            select @套管螺纹保护环,@油管螺纹保护环,@稀释剂,@油漆,@打包带,@螺纹脂,@色环漆,@接箍漆,@白墨,@草支垫,@油管光管,@套管光管,@油管接箍光管,@套管接箍光管,@成品接箍,@套管N80光管

            ";
            sql0 = sql0.Replace("@年度", this.Year0.SelectedValue);
            sql0 = sql0.Replace("@月份", this.Month0.SelectedValue);
            Cmd.CommandText = sql0;
           SqlDataReader Reader = Cmd.ExecuteReader();
           if (Reader.Read())
           {
               tglbhlant = Reader.GetInt32(0);
               yglbhlant = Reader.GetInt32(1);
               稀释剂plant = Reader.GetInt32(2);
               黑色油漆plant = Reader.GetInt32(3);
               打包带plant = Reader.GetInt32(4);
               螺纹脂plant = Reader.GetDouble(5);
               白色环漆plant = Reader.GetDouble(6);
               接箍漆plant = Reader.GetDouble(7);
               白墨plant = Reader.GetInt32(8);
               草支垫plant = Reader.GetInt32(9);
               yggplant =Reader.GetDouble(10);
               tggplant = Reader.GetDouble(11);
               ygjgplant =Reader.GetDouble(12);
               tgjgplant = Reader.GetDouble(13);
               cpjgplant =Reader.GetDouble(14);
               tggN80plant = Reader.GetDouble(15);
           }
           Reader.Close();
          string sql2 = @"if not EXISTS(select * from 生产处原辅料计划购进 where 年度=@年度 and 月份=@月份)
            begin
            
            insert into 生产处原辅料计划购进 values(@年度,@月份,@油管光管,@套管光管,@油管接箍光管,@套管接箍光管,@成品接箍,@套管螺纹保护环,@油管螺纹保护环,@稀释剂,@油漆,'0',@打包带,@螺纹脂,@色环漆,@接箍漆,@白墨,@草支垫,'0')
            end
            else
            begin
            update 生产处原辅料计划购进 set 油管光管计划购进=@油管光管,套管光管计划购进=@套管光管,油管接箍管计划购进=@油管接箍光管,套管接箍管计划购进=@套管接箍光管,成品接箍计划购进=@成品接箍,套管螺纹保护环=@套管螺纹保护环,油管螺纹保护环=@油管螺纹保护环,稀释剂=@稀释剂,油漆=@油漆,打包带=@打包带,螺纹脂=@螺纹脂,色环漆=@色环漆,接箍漆=@接箍漆,白墨=@白墨,草支垫=@草支垫 where 年度=@年度 and 月份=@月份
            end";
            sql2 = sql2.Replace("@年度", this.Year0.SelectedValue);
            sql2 = sql2.Replace("@月份", this.Month0.SelectedValue);
            //
            sql2 = sql2.Replace("@油管光管", yggplant.ToString());
            sql2 = sql2.Replace("@套管光管", tggplant.ToString());
            sql2 = sql2.Replace("@油管接箍光管", ygjgplant.ToString());
            sql2 = sql2.Replace("@套管接箍光管", tgjgplant.ToString());
            sql2 = sql2.Replace("@成品接箍", cpjgplant.ToString());
            
            //辅料
            sql2 = sql2.Replace("@套管螺纹保护环", tglbhlant.ToString());
            sql2 = sql2.Replace("@油管螺纹保护环", yglbhlant.ToString());
            sql2 = sql2.Replace("@稀释剂", 稀释剂plant.ToString());
            sql2 = sql2.Replace("@油漆", 黑色油漆plant.ToString());
            sql2 = sql2.Replace("@打包带", 打包带plant.ToString());
            sql2 = sql2.Replace("@螺纹脂", 螺纹脂plant.ToString());
            sql2 = sql2.Replace("@色环漆", 白色环漆plant.ToString());
            sql2 = sql2.Replace("@接箍漆", 接箍漆plant.ToString());
            sql2 = sql2.Replace("@白墨", 白墨plant.ToString());
            sql2 = sql2.Replace("@草支垫", 草支垫plant.ToString());
            Cmd.CommandText = sql2;
            Cmd.ExecuteNonQuery();
            Cmd.CommandText = "select count(*) from 生产处原辅料计划购进 where 年度=" + this.Year0.SelectedValue + " and 月份=" + this.Month0.Text + "";
            this.Message.Text = "·准备就绪";
            if ((int)Cmd.ExecuteScalar() == 0)
            {
                //this.Button_Plan_In.Text = "录入计划量";
                //this.Button_Plan_In.Visible = true;
                //this.Button_Save0.Visible = true;
            }
            else
            {
                //this.Button_Plan_In.Visible = true;
                //this.Button_Plan_In.Text = "修改计划量";
                //this.Button_Save0.Visible = true;
                this.R1.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 1)).ReadOnly = true;
                this.R2.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 2)).ReadOnly = true;
                this.R3.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 3)).ReadOnly = true;
                this.R4.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 4)).ReadOnly = true;
                this.R5.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 5)).ReadOnly = true;
            }
            Cmd.CommandText = @"     
            select isnull(sum(油管光管计划购进),0),isnull(sum(套管光管计划购进),0),isnull(sum(油管接箍管计划购进),0),isnull(sum(套管接箍管计划购进),0),isnull(sum(成品接箍计划购进),0),isnull(sum(套管螺纹保护环),0),isnull(sum(油管螺纹保护环),0),isnull(sum(稀释剂),0),isnull(sum(油漆),0),isnull(sum(打包带),0),isnull(sum(螺纹脂),0),isnull(sum(色环漆),0),isnull(sum(接箍漆),0),isnull(sum(白墨),0),isnull(sum(草支垫),0) from 生产处原辅料计划购进 where 年度='" + this.Year0.SelectedValue + "' and 月份='" + this.Month0.SelectedValue + "'";
             Reader = Cmd.ExecuteReader();
            //实有库存
            if (Reader.Read())
            {
                yggplant = Reader.GetInt32(0);
                tggplant = Reader.GetInt32(1);
                ygjgplant = Reader.GetInt32(2);
                tgjgplant = Reader.GetInt32(3);
                cpjgplant = Reader.GetInt32(4);
                tglbhlant = Reader.GetInt32(5);
                yglbhlant = Reader.GetInt32(6);
                稀释剂plant = Reader.GetInt32(7);
                黑色油漆plant = Reader.GetInt32(8);               
                打包带plant = Reader.GetInt32(9);
                螺纹脂plant = Reader.GetDouble(10);
                白色环漆plant = Reader.GetDouble(11);
                接箍漆plant = Reader.GetDouble(12);
                白墨plant = Reader.GetInt32(13);
                草支垫plant = Reader.GetInt32(14);
               
            }
            Reader.Close();
            this.R1.Text = tggplant.ToString();
            this.R2.Text = tggN80plant.ToString();
            this.R3.Text = yggplant.ToString();
            this.R4.Text = ygjgplant.ToString();
            this.R5.Text = tgjgplant.ToString();
            this.R6.Text = cpjgplant.ToString();
            this.R7.Text = tglbhlant.ToString();
            this.R8.Text = yglbhlant.ToString();
            this.R9.Text = 稀释剂plant.ToString();
            this.R10.Text = 黑色油漆plant.ToString();        
            this.R11.Text = 打包带plant.ToString();
            this.R12.Text = 螺纹脂plant.ToString();
            this.R13.Text = 白色环漆plant.ToString();
            this.R14.Text = 接箍漆plant.ToString();
            this.R15.Text = 白墨plant.ToString();
            this.R16.Text = 草支垫plant.ToString();
            //原料实际购进
            string sql = @" 
            declare @yc datetime   
            declare @ym datetime 
            declare @油管光管到货量 float
            declare @套管光管到货量 float
            declare @套管N80光管到货量 float
            declare @油管接箍管到货量 float
            declare @套管接箍管到货量 float
            declare @套管成品接箍到货量 float
           
            select @yc=起始日期,@ym=截止日期 from  生产月设置 where  分厂=0 and 年度=@年份 and 月份=@月份

           

            select @油管光管到货量=[dbo].[原料本期收入](@年份,@月份,1)
            select @套管光管到货量=[dbo].[原料本期收入](@年份,@月份,2)
            select @套管N80光管到货量=[dbo].[原料本期收入](@年份,@月份,102)
            select @油管接箍管到货量=[dbo].[原料本期收入](@年份,@月份,3)
            select @套管接箍管到货量=[dbo].[原料本期收入](@年份,@月份,4)
            select @套管成品接箍到货量=[dbo].[原料本期收入](@年份,@月份,6)
           
           
            select @油管光管到货量,@套管光管到货量,@油管接箍管到货量,@套管接箍管到货量,@套管成品接箍到货量,@套管N80光管到货量";
            sql = sql.Replace("@年份", this.Year0.SelectedValue);
            sql = sql.Replace("@月份", this.Month0.SelectedValue);
            // select @油管光管到货量=isnull(sum(总重量),0) from 原料到发记录 where 原料ID=1 and 到货日期 between @yc and @ym 
            //select @套管光管到货量=isnull(sum(总重量),0) from 原料到发记录 where 原料ID=2 and 到货日期 between @yc and @ym
            //select @套管N80光管到货量=isnull(sum(总重量),0) from 原料到发记录 where 原料ID=102 and 到货日期 between @yc and @ym
            //select @油管接箍管到货量=isnull(sum(总重量),0) from 原料到发记录 where 原料ID=3 and 到货日期 between @yc and @ym
            //select @套管接箍管到货量=isnull(sum(总重量),0) from 原料到发记录 where 原料ID=4 and 到货日期 between @yc and @ym
            //select @套管成品接箍到货量=isnull(sum(总重量),0) from 原料到发记录 where 原料ID=6 and 到货日期 between @yc and @ym
            Cmd.CommandText = sql;
            Reader = Cmd.ExecuteReader();
            if (Reader.Read())
            {
                ygg本月购进 = Reader.GetDouble(0);
                tgg本月购进 = Reader.GetDouble(1);
                ygjg本月购进 = Reader.GetDouble(2);
                tgjg本月购进 = Reader.GetDouble(3);
                cpjg本月购进 = Reader.GetDouble(4);
                tggN80本月购进 = Reader.GetDouble(5);
            }
            Reader.Close();
            //材料实际购进
            string sql1 = @" 
            declare @yc datetime   
            declare @ym datetime 
            declare @yglbh本月购进 int
            declare @tglbh本月购进 int
            declare @稀释剂本月购进1 float
            declare @稀释剂本月购进2 float
            declare @稀释剂本月购进 float
            declare @黑色油漆本月购进 float
            declare @打包带本月购进 float
            declare @螺纹脂本月购进 float
            declare @白色环漆本月购进 float
            declare @接箍漆本月购进 float
            declare @白墨本月购进 int
            declare @草支垫本月购进 int

            select  @yc=起始日期,@ym=截止日期 from  生产月设置 where  分厂=0 and 年度=@年份 and 月份=@月份
            select  @yglbh本月购进=isnull(sum(数量),0) from 材料到发货  where 发货=0 and 材料ID=0700000001 and 日期 between @yc and @ym
            select  @tglbh本月购进=isnull(sum(数量),0) from 材料到发货   where 发货=0 and 材料ID=0700000002 and 日期 between @yc and @ym 
            select  @稀释剂本月购进1=isnull(sum(数量),0) from 材料到发货 where 发货=0 and 材料ID=0301000003 and 日期 between @yc and @ym
            select  @稀释剂本月购进2=isnull(sum(数量),0) from 材料到发货 where 发货=0 and 材料ID=0301000004 and 日期 between @yc and @ym
            select  @稀释剂本月购进=@稀释剂本月购进1+@稀释剂本月购进2
            select  @黑色油漆本月购进=isnull(sum(数量),0) from 材料到发货 where 发货=0 and 材料ID=0301000001 and 日期 between @yc and @ym 
            select  @打包带本月购进=isnull(sum(数量),0) from 材料到发货   where 发货=0 and 材料ID=0401000001 and 日期 between @yc and @ym  
            select  @螺纹脂本月购进=isnull(sum(数量),0) from 材料到发货 where 发货=0 and 材料ID=0302000001 and 日期 between @yc and @ym
            select  @白色环漆本月购进=isnull(sum(数量),0) from 材料到发货 where 发货=0 and 材料ID=0301000006 and 日期 between @yc and @ym 
            select  @接箍漆本月购进=isnull(sum(数量),0) from 材料到发货   where 发货=0 and 材料ID=0301000005 and 日期 between @yc and @ym  
            select  @白墨本月购进=isnull(sum(数量),0) from 材料到发货 where 发货=0 and 材料ID=0303000007 and 日期 between @yc and @ym 
            select  @草支垫本月购进=isnull(sum(数量),0) from 材料到发货   where 发货=0 and 材料ID=0700000003 and 日期 between @yc and @ym  

           select @yglbh本月购进,@tglbh本月购进,@稀释剂本月购进,@黑色油漆本月购进,@打包带本月购进,@螺纹脂本月购进,@白色环漆本月购进,@接箍漆本月购进,@白墨本月购进,@草支垫本月购进";
            sql1 = sql1.Replace("@年份", this.Year0.SelectedValue);
            sql1 = sql1.Replace("@月份", this.Month0.SelectedValue);
            Cmd.CommandText = sql1;
            Reader = Cmd.ExecuteReader();
            if (Reader.Read())
            {
                yglbh本月购进 = Reader.GetInt32(0);
                tglbh本月购进 = Reader.GetInt32(1);
                稀释剂本月购进 = Reader.GetDouble(2);
                黑色油漆本月购进 = Reader.GetDouble(3);
                打包带本月购进 = Reader.GetDouble(4);
                螺纹脂本月购进 = Reader.GetDouble(5);
                白色环漆本月购进 = Reader.GetDouble(6);
                接箍漆本月购进 = Reader.GetDouble(7);
                白墨本月购进 = Reader.GetInt32(8);
                草支垫本月购进 = Reader.GetInt32(9);               
            }
            Reader.Close();
            if (tggplant == 0)
            {
                tgg完成率 = 0;
            }
            else
            {
                tgg完成率 = (tgg本月购进 / tggplant * 100);
            }
            if (tggN80plant == 0)
            {
                tggN80完成率 = 0;
            }
            else
            {
                tggN80完成率 = (tggN80本月购进 / tggN80plant * 100);
            }
            if (yggplant == 0)
            {
                ygg完成率 = 0;
            }
            else
            {
                ygg完成率 = (ygg本月购进 / yggplant * 100);
            }
            if (ygjgplant == 0)
            {
                ygjg完成率 = 0;
            }
            else
            {
                ygjg完成率 = (ygjg本月购进 / ygjgplant * 100);
            }
            if (tgjgplant == 0)
            {
                tgjg完成率 = 0;
            }
            else
            {
                tgjg完成率 = (tgjg本月购进 / tgjgplant * 100);
            }
            if (cpjgplant == 0)
            {
                cpjg完成率 = 0;
            }
            else
            {
                cpjg完成率 = (cpjg本月购进 / cpjgplant * 100);
            }
            if (yglbhlant == 0)
            {
                yglbh完成率 = 0;
            }
            else
            {
                yglbh完成率 = (yglbh本月购进 / yglbhlant * 100);
            }
            if (tglbhlant == 0)
            {
                tglbh完成率 = 0;
            }
            else
            {
                tglbh完成率 = (tglbh本月购进 /tglbhlant * 100);
            }
            if (稀释剂plant == 0)
            {
                稀释剂完成率 = 0;
            }
            else
            {
                稀释剂完成率 = (稀释剂本月购进 / 稀释剂plant * 100);
            }
            if (黑色油漆plant == 0)
            {
                黑色油漆完成率 = 0;
            }
            else
            {
                黑色油漆完成率 = (黑色油漆本月购进 / 黑色油漆plant * 100);
            }
            if (打包带plant == 0)
            {
                打包带完成率 = 0;
            }
            else
            {
                打包带完成率 = (打包带本月购进 / 打包带plant * 100);
            }
            if (螺纹脂plant == 0)
            {
                螺纹脂完成率 = 0;
            }
            else
            {
                螺纹脂完成率 = (螺纹脂本月购进 / 螺纹脂plant * 100);
            }
            if (白色环漆plant == 0)
            {
                白色环漆完成率 = 0;
            }
            else
            {
                白色环漆完成率 = (白色环漆本月购进 / 白色环漆plant * 100);
            }
            if (接箍漆plant == 0)
            {
                接箍漆完成率 = 0;
            }
            else
            {
                接箍漆完成率 = (接箍漆本月购进 / 接箍漆plant * 100);
            }
            if (白墨plant == 0)
            {
                白墨完成率 = 0;
            }
            else
            {
                白墨完成率 = (白墨本月购进 / 白墨plant * 100);
            }
            if (草支垫plant == 0)
            {
                草支垫完成率 = 0;
            }
            else
            {
                草支垫完成率 = (草支垫本月购进 / 草支垫plant * 100);
            }              
            Conn.Close();        
            Reader.Dispose();
            Cmd.Dispose();
            Conn.Dispose();
        }
        protected void WriteToFile()
        {

            Response.ContentType = "application/ms-excel";
            Response.AddHeader("content-disposition", "attachment; filename=\"" + DateTime.Now.ToShortDateString() + ".xls\"");
            hssfworkbook.Write(Response.OutputStream);
        }

        protected void InitializeWorkbook()
        {

            FileStream file = new FileStream(HttpContext.Current.Server.MapPath("/Produce/模板/原辅料采购计划完成情况.xls"), FileMode.Open, FileAccess.Read);

            hssfworkbook = new HSSFWorkbook(file);

            DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
            dsi.Company = "原辅料采购计划完成情况";
            hssfworkbook.DocumentSummaryInformation = dsi;

            SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
            si.Subject = "报表";
            si.Title = "原辅料采购计划完成情况";
            hssfworkbook.SummaryInformation = si;
        }
        protected void Button_Save_Click(object sender, EventArgs e)
        {
            InitializeWorkbook();
            HSSFSheet sheet1 = hssfworkbook.GetSheet("原辅料采购计划完成情况");
            Button_Query_Click(null, null);
            sheet1.GetRow(0).GetCell(0).SetCellValue(this.Month0.SelectedItem.Text + "月份主要原、辅材料采购计划完成情况");

            sheet1.GetRow(3).GetCell(3).SetCellValue(tggplant);
            sheet1.GetRow(3).GetCell(4).SetCellValue(tgg本月购进);
            sheet1.GetRow(3).GetCell(5).SetCellValue(tgg完成率.ToString("0.00"));

            sheet1.GetRow(4).GetCell(3).SetCellValue(tggN80plant);
            sheet1.GetRow(4).GetCell(4).SetCellValue(tggN80本月购进);
            sheet1.GetRow(4).GetCell(5).SetCellValue(tggN80完成率.ToString("0.00"));


            sheet1.GetRow(5).GetCell(3).SetCellValue(yggplant);
            sheet1.GetRow(5).GetCell(4).SetCellValue(ygg本月购进);
            sheet1.GetRow(5).GetCell(5).SetCellValue(ygg完成率.ToString("0.00"));


            sheet1.GetRow(6).GetCell(3).SetCellValue(ygjgplant);
            sheet1.GetRow(6).GetCell(4).SetCellValue(ygjg本月购进);         
            sheet1.GetRow(6).GetCell(5).SetCellValue(ygjg完成率.ToString("0.00"));

            sheet1.GetRow(7).GetCell(3).SetCellValue(tgjgplant);
            sheet1.GetRow(7).GetCell(4).SetCellValue(tgjg本月购进);        
            sheet1.GetRow(7).GetCell(5).SetCellValue(tgjg完成率.ToString("0.00"));

            sheet1.GetRow(8).GetCell(3).SetCellValue(cpjgplant);
            sheet1.GetRow(8).GetCell(4).SetCellValue(cpjg本月购进);
            sheet1.GetRow(8).GetCell(5).SetCellValue(cpjg完成率.ToString("0.00"));

            sheet1.GetRow(9).GetCell(3).SetCellValue(tglbhlant);
            sheet1.GetRow(9).GetCell(4).SetCellValue(tglbh本月购进);
            sheet1.GetRow(9).GetCell(5).SetCellValue(tglbh完成率.ToString("0.00"));

            sheet1.GetRow(10).GetCell(3).SetCellValue(yglbhlant);
            sheet1.GetRow(10).GetCell(4).SetCellValue(yglbh本月购进);
            sheet1.GetRow(10).GetCell(5).SetCellValue(yglbh完成率.ToString("0.00"));

            sheet1.GetRow(11).GetCell(3).SetCellValue(稀释剂plant);
            sheet1.GetRow(11).GetCell(4).SetCellValue(稀释剂本月购进);
            sheet1.GetRow(11).GetCell(5).SetCellValue(稀释剂完成率.ToString("0.00"));

            sheet1.GetRow(12).GetCell(3).SetCellValue(黑色油漆plant);
            sheet1.GetRow(12).GetCell(4).SetCellValue(黑色油漆本月购进);
            sheet1.GetRow(12).GetCell(5).SetCellValue(黑色油漆完成率.ToString("0.00"));

            sheet1.GetRow(13).GetCell(3).SetCellValue(打包带plant);
            sheet1.GetRow(13).GetCell(4).SetCellValue(打包带本月购进);
            sheet1.GetRow(13).GetCell(5).SetCellValue(打包带完成率.ToString("0.00"));


            sheet1.GetRow(14).GetCell(3).SetCellValue(螺纹脂plant);
            sheet1.GetRow(14).GetCell(4).SetCellValue(螺纹脂本月购进);
            sheet1.GetRow(14).GetCell(5).SetCellValue(螺纹脂完成率.ToString("0.00"));

            sheet1.GetRow(15).GetCell(3).SetCellValue(白色环漆plant);
            sheet1.GetRow(15).GetCell(4).SetCellValue(白色环漆本月购进);
            sheet1.GetRow(15).GetCell(5).SetCellValue(白色环漆完成率.ToString("0.00"));


            sheet1.GetRow(16).GetCell(3).SetCellValue(接箍漆plant);
            sheet1.GetRow(16).GetCell(4).SetCellValue(接箍漆本月购进);
            sheet1.GetRow(16).GetCell(5).SetCellValue(接箍漆完成率.ToString("0.00"));

            sheet1.GetRow(17).GetCell(3).SetCellValue(白墨plant);
            sheet1.GetRow(17).GetCell(4).SetCellValue(白墨本月购进);
            sheet1.GetRow(17).GetCell(5).SetCellValue(白墨完成率.ToString("0.00"));


            sheet1.GetRow(18).GetCell(3).SetCellValue(草支垫plant);
            sheet1.GetRow(18).GetCell(4).SetCellValue(草支垫本月购进);
            sheet1.GetRow(18).GetCell(5).SetCellValue(草支垫完成率.ToString("0.00"));
      

            WriteToFile();
            Response.End();
        }

        protected void Button_Plan_In_Click(object sender, EventArgs e)
        {
            this.R1.CssClass = "textbox";
            this.R1.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 1)).ReadOnly = false;
            this.R2.CssClass = "textbox";
            this.R2.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 2)).ReadOnly = false;
            this.R3.CssClass = "textbox";
            this.R3.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 3)).ReadOnly = false;
            this.R4.CssClass = "textbox";
            this.R4.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 4)).ReadOnly = false;
            this.R5.CssClass = "textbox";
            this.R5.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 5)).ReadOnly = false;
            this.R6.CssClass = "textbox";
            this.R6.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 6)).ReadOnly = false;
            this.R7.CssClass = "textbox";
            this.R7.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 7)).ReadOnly = false;
            this.R8.CssClass = "textbox";
            this.R8.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 8)).ReadOnly = false;
            this.R9.CssClass = "textbox";
            this.R9.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 9)).ReadOnly = false;
            this.R10.CssClass = "textbox";
            this.R10.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 10)).ReadOnly = false;
            this.R11.CssClass = "textbox";
            this.R11.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 11)).ReadOnly = false;
            this.R12.CssClass = "textbox";
            this.R12.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 12)).ReadOnly = false;
            this.R13.CssClass = "textbox";
            this.R13.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 13)).ReadOnly = false;
            this.R14.CssClass = "textbox";
            this.R14.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 14)).ReadOnly = false;
            this.R15.CssClass = "textbox";
            this.R15.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 15)).ReadOnly = false;
        }

        protected void Button_Save0_Click(object sender, EventArgs e)
        {
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.CommandText = "if EXISTS(select * from 生产处原辅料计划购进 where 年度=" + this.Year0.SelectedValue + " and 月份=" + this.Month0.Text + " )\n"
            + "begin\n"
            + "update 生产处原辅料计划购进 set 油管光管计划购进='" + int.Parse(this.R1.Text) + "',套管光管计划购进='" + int.Parse(this.R2.Text) + "',油管接箍管计划购进='" + int.Parse(this.R3.Text) + "',套管接箍管计划购进='" + int.Parse(this.R4.Text) + "',成品接箍计划购进='" + int.Parse(this.R5.Text) + "'\n"
            + ",套管螺纹保护环='" + int.Parse(this.R6.Text) + "',油管螺纹保护环='" + int.Parse(this.R7.Text) + "',稀释剂='" + int.Parse(this.R8.Text) + "',油漆='" + int.Parse(this.R9.Text) + "'\n"
            + " ,打包带='" + int.Parse(this.R10.Text) + "',螺纹脂='" + int.Parse(this.R11.Text) + "',色环漆='" + int.Parse(this.R12.Text) + "',接箍漆='" + double.Parse(this.R13.Text) + "' \n"
            + " ,白墨='" + int.Parse(this.R14.Text) + "',草支垫='" + int.Parse(this.R15.Text) + "' \n"
            + "where 年度='" + this.Year0.SelectedValue + "' and 月份='" + this.Month0.SelectedValue + "'\n"
            + "end\n"
            + "else\n"
            + "begin\n"
            + @"insert into 生产处原辅料计划购进 values('" + this.Year0.Text + "','" + this.Month0.Text + "','" + int.Parse(this.R2.Text) + "','" + int.Parse(this.R1.Text) + "','" + int.Parse(this.R3.Text) + "','" + int.Parse(this.R4.Text) + "','" + int.Parse(this.R5.Text) + "','" + int.Parse(this.R6.Text) + "','" + int.Parse(this.R7.Text) + "','" + int.Parse(this.R8.Text) + "','" + int.Parse(this.R9.Text) + "','"+0+"','" + int.Parse(this.R10.Text) + "','" + double.Parse(this.R11.Text) + "','" + double.Parse(this.R12.Text) + "','" + double.Parse(this.R13.Text) + "','" + int.Parse(this.R14.Text) + "','" + int.Parse(this.R15.Text) + "','" + 0+"')\n"
            + "end";
            if (Cmd.ExecuteNonQuery() < 1)
            {
                this.Message.Text = ".保存失败!";
            }
            else
            {
                this.Message.Text = ".保存成功!";
                this.Button_Plan_In.Visible = false;
                this.Button_Save0.Visible = false;
                this.R1.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 1)).ReadOnly = true;
                this.R2.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 2)).ReadOnly = true;
                this.R3.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 3)).ReadOnly = true;
                this.R4.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 4)).ReadOnly = true;
                this.R5.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 5)).ReadOnly = true;
                this.R6.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 6)).ReadOnly = true;
                this.R7.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 7)).ReadOnly = true;
                this.R8.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 8)).ReadOnly = true;
                this.R9.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 9)).ReadOnly = true;
                this.R10.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 10)).ReadOnly = true;
                this.R11.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 11)).ReadOnly = true;
                this.R12.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 12)).ReadOnly = true;
                this.R13.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 13)).ReadOnly = true;
                this.R14.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 14)).ReadOnly = true;
                this.R15.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 15)).ReadOnly = true;           
            }
            Conn.Close();
            Cmd.Dispose();
            Conn.Dispose();
        }

        protected void Year0_SelectedIndexChanged(object sender, EventArgs e)
        {
            Button_Plan_In.Visible = false;
            this.Button_Save0.Visible = false;
            ((TextBox)this.FindControl("R" + 1)).Text = "0";
            ((TextBox)this.FindControl("R" + 1)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 1)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 2)).Text = "0";
            ((TextBox)this.FindControl("R" + 2)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 2)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 3)).Text = "0";
            ((TextBox)this.FindControl("R" + 3)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 3)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 4)).Text = "0";
            ((TextBox)this.FindControl("R" + 4)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 4)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 5)).Text = "0";
            ((TextBox)this.FindControl("R" + 5)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 5)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 6)).Text = "0";
            ((TextBox)this.FindControl("R" + 6)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 6)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 7)).Text = "0";
            ((TextBox)this.FindControl("R" + 7)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 7)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 8)).Text = "0";
            ((TextBox)this.FindControl("R" + 8)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 8)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 9)).Text = "0";
            ((TextBox)this.FindControl("R" + 9)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 9)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 10)).Text = "0";
            ((TextBox)this.FindControl("R" + 10)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 10)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 11)).Text = "0";
            ((TextBox)this.FindControl("R" + 11)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 11)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 12)).Text = "0";
            ((TextBox)this.FindControl("R" + 12)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 12)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 13)).Text = "0";
            ((TextBox)this.FindControl("R" + 13)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 13)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 14)).Text = "0";
            ((TextBox)this.FindControl("R" + 14)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 14)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 15)).Text = "0";
            ((TextBox)this.FindControl("R" + 15)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 15)).CssClass = "blank_center";
            Button_Query_Click(null, null);
        }

        protected void Month0_SelectedIndexChanged(object sender, EventArgs e)
        {
            Button_Plan_In.Visible = false;
            this.Button_Save0.Visible = false;
            ((TextBox)this.FindControl("R" + 1)).Text = "0";
            ((TextBox)this.FindControl("R" + 1)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 1)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 2)).Text = "0";
            ((TextBox)this.FindControl("R" + 2)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 2)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 3)).Text = "0";
            ((TextBox)this.FindControl("R" + 3)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 3)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 4)).Text = "0";
            ((TextBox)this.FindControl("R" + 4)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 4)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 5)).Text = "0";
            ((TextBox)this.FindControl("R" + 5)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 5)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 6)).Text = "0";
            ((TextBox)this.FindControl("R" + 6)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 6)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 7)).Text = "0";
            ((TextBox)this.FindControl("R" + 7)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 7)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 8)).Text = "0";
            ((TextBox)this.FindControl("R" + 8)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 8)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 9)).Text = "0";
            ((TextBox)this.FindControl("R" + 9)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 9)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 10)).Text = "0";
            ((TextBox)this.FindControl("R" + 10)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 10)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 11)).Text = "0";
            ((TextBox)this.FindControl("R" + 11)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 11)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 12)).Text = "0";
            ((TextBox)this.FindControl("R" + 12)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 12)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 13)).Text = "0";
            ((TextBox)this.FindControl("R" + 13)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 13)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 14)).Text = "0";
            ((TextBox)this.FindControl("R" + 14)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 14)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 15)).Text = "0";
            ((TextBox)this.FindControl("R" + 15)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 15)).CssClass = "blank_center";
            Button_Query_Click(null, null);
        }
    }
}
